<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.css" rel="stylesheet">
    <link rel="stylesheet" href="./css/pagination.css">
    <script src="./js/pagination.js"></script>
    <script src="./js/jquery/jquery.js"></script>
    <script src="./js/bootstarp/bootstrap.js"></script>
    <!--../ 表示返回上一层-->
    <script>
        //时间格式化函数
        function timeFormat(data) {
            let date = new Date(data)
            let Y = date.getFullYear() + '-'
            let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
            let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
            let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
            let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
            let s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds())
            return Y + M + D + h + m + s
        }

        $(function () {
            let id = getQueryString("id");
            let params = {
                id: id
            }
            $.get("http://127.0.0.1:8080/ad/update",params,function (result) {
                //边创建边获取数据
                if (result.status === 200) {
                    let datum = result.data;
                    $("#id").val(datum.id);
                    $("#status").val(datum.status);
                    $("#name").val(datum.name);
                    $("#associateditems").val(datum.associateditems);
                    $("#starttime").val(timeFormat(datum.starttime));
                    $("#endtime").val(timeFormat(datum.endtime));
                    $("#visitors").val(datum.visitors);
                    $("#createtime").val(timeFormat(datum.createtime));
                }
            })
            //保存数据
            $("#edit").click(function (){
                let admins = {}
                admins.id = id;
                admins.status = $("#status").val();
                admins.name = $("#name").val();
                admins.associateditems = $("#associateditems").val();
                admins.starttime = $("#starttime").val();
                admins.endtime = $("#endtime").val();
                admins.visitors = $("#visitors").val();
                admins.createtime = $("#createtime").val();
                let data={
                    data:JSON.stringify(admins)
                }
                $.post("http://127.0.0.1:8080/ad/list",data,function (result){
                    //返回广告管理界面
                    window.location.href="admsg.html";
                })
            });
        })

        function getQueryString(name) {
            let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            let r = window.location.search.substr(1).match(reg);
            return r != null ? unescape(r[2]) : null
        }
    </script>
</head>
<body>
<div class="box container-fluid">
    <form name="nameform">
        <div class="form-group">
            <label for="status">状态值：</label>
            <input id="status" type="text" class="form-control"  placeholder="0 表示未上架 1 表示已上架 2 表示已下架" style="width: 300px" onkeyup="this.value=this.value.replace(/\s+/g,'')">
            <span id="sp"></span>
        </div>
        <div class="form-group">
            <label for="name">广告名称：</label>
            <input id="name" type="text" class="form-control" placeholder="输入广告名称" style="width: 300px" onkeyup="this.value=this.value.replace(/\s+/g,'')">
            <span id="sp2"></span>
        </div>
        <div class="form-group">
            <label for="associateditems">关联项目：</label>
            <input id="associateditems" type="text" class="form-control" placeholder="输入关联项目" style="width: 300px" onkeyup="this.value=this.value.replace(/\s+/g,'')">
            <span id="sp3"></span>
        </div>
        <div class="form-group">
            <label for="starttime">有效期开始时间：</label>
            <input id="starttime" type="text" class="form-control" placeholder="输入有效期开始时间" style="width: 300px" onkeyup="this.value=this.value.replace(/\s+/g,'')">
            <span id="sp4"></span>
        </div>
        <div class="form-group">
            <label for="endtime">有效期结束时间：</label>
            <input id="endtime" type="text" class="form-control" placeholder="输入有效期结束时间" style="width: 300px" onkeyup="this.value=this.value.replace(/\s+/g,'')">
            <span id="sp5"></span>
        </div>
        <div class="form-group">
            <label for="visitors">访问人数：</label>
            <input id="visitors" type="text" class="form-control" placeholder="输入访问人数" style="width: 300px" onkeyup="this.value=this.value.replace(/\s+/g,'')">
            <span id="sp6"></span>
        </div>
        <div class="form-group">
            <label for="createtime">创建时间：</label>
            <input id="createtime" type="text" class="form-control" placeholder="输入创建时间" style="width: 300px" onkeyup="this.value=this.value.replace(/\s+/g,'')">
            <span id="sp7"></span>
        </div>
    </form>
</div>
<div class="row">
    <div class="col-md-4"></div>
    <div class="form-group col-md-4">
        <label for="save"></label>
        <input type="button" class="btn btn-info" value="取消">
        <input id="save" type="button" class="btn btn-info" value="保存">
    </div>
    <div class="col-md-4">
    </div>
</div>
</body>
</html>